from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from datetime import datetime

class Registration(models.Model):
    user = models.ForeignKey(User, verbose_name=_(u'Usuario'), related_name='registration', unique=True)
    key = models.CharField(_(u'Clave'), max_length=32, unique=True)
    completed = models.BooleanField(_(u'Registro completo'), default=False)
    datetime = models.DateTimeField(_(u'Fecha y hora'))

    def save(self):
        if self.id == None:
            self.datetime = datetime.now()
        super(Registration, self).save()

    def get_key(self):
        return self.key

    def get_date(self):
        return _(u'%(day)i/%(month)i/%(year)i') % { 'day': self.datetime.day, 'month': self.datetime.month, 'year': self.datetime.year }

    class Admin:
        pass
